package com.dingmouren.smaple.paletteimageview.slice;

import com.dingmouren.paletteimageview.PaletteImageView;
import com.dingmouren.smaple.paletteimageview.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Slider;

public class ShadowImageAbilitySlice extends BaseAbilitySlice implements Slider.ValueChangedListener {

    private PaletteImageView paletteImageView;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_shadow_image);
        initView();
    }

    public void initView() {
        paletteImageView = findComponent(ResourceTable.Id_palette);
        Slider sImgRadius = findComponent(ResourceTable.Id_img_radius_progress);
        Slider sShadowRadius = findComponent(ResourceTable.Id_shadow_radius_progress);
        Slider sOffsetX = findComponent(ResourceTable.Id_x_progress);
        Slider sOffsetY = findComponent(ResourceTable.Id_y_progress);
        paletteImageView.setShadowColor(0xff795548);
        sImgRadius.setValueChangedListener(this);
        sShadowRadius.setValueChangedListener(this);
        sOffsetX.setValueChangedListener(this);
        sOffsetY.setValueChangedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onProgressUpdated(Slider slider, int progress, boolean b) {
        switch (slider.getId()) {
            case ResourceTable.Id_img_radius_progress:
                paletteImageView.setPaletteRadius(progress * 500 / 100);
                break;
            case ResourceTable.Id_shadow_radius_progress:
                paletteImageView.setPaletteShadowRadius(progress);
                break;
            case ResourceTable.Id_x_progress:
                paletteImageView.setPaletteShadowOffset(progress, 0);
                break;
            case ResourceTable.Id_y_progress:
                paletteImageView.setPaletteShadowOffset(0, progress);
                break;
        }
    }


    @Override
    public void onTouchStart(Slider slider) {
    }

    @Override
    public void onTouchEnd(Slider slider) {
    }
}
